﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Com.AAS.Toolbox.DataMirror.Setting
{
    public class NotifyIconForm : System.Windows.Forms.Form
    {

        private NotifyIcon m_NotifyIcon;
        private List<MenuItem> m_MenuItems = new List<MenuItem>();

        private String notifyTitle = "Notify Brid";
        private Icon notifyLogo;

        public event EventHandler NotifyDoubleClick;


        public NotifyIconForm(String title, Icon logo, MenuItem[] menus)
        {
            InitializeComponent();

            this.notifyTitle = title;
            this.notifyLogo = logo;

            this.Load += NotifyIconForm_Load;
            this.Disposed += NotifyIconForm_Disposed;

            if (menus != null)
                m_MenuItems.AddRange(menus);
        }

        void NotifyIconForm_Disposed(object sender, EventArgs e)
        {

        }

        void NotifyIconForm_Load(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Minimized;
            this.m_NotifyIcon.Icon = notifyLogo;
            this.m_NotifyIcon.Text = notifyTitle;
            this.m_NotifyIcon.DoubleClick += NotifyDoubleClick;

            MenuItem menuItemExit = new MenuItem("(&X)Exit");
            menuItemExit.Click += new System.EventHandler(menuItemExit_Click);
            m_MenuItems.Add(menuItemExit);

            this.m_NotifyIcon.ContextMenu = new ContextMenu(m_MenuItems.ToArray());
        }             

        private void menuItemExit_Click(object sender, EventArgs e)
        {
            this.m_NotifyIcon.Visible = false;
            this.Close();
        }


        #region VS Auto Created code

        private NotifyIconForm()
        {

        }

        private IContainer components;

        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            this.m_NotifyIcon = new System.Windows.Forms.NotifyIcon(this.components);
            this.SuspendLayout();
            // 
            // m_NotifyIcon
            // 
            this.m_NotifyIcon.Text = "notifyIcon1";
            this.m_NotifyIcon.Visible = true;
            // 
            // NotifyIconForm
            // 
            this.ClientSize = new System.Drawing.Size(261, 84);
            this.Name = "NotifyIconForm";
            this.ShowIcon = false;
            this.ShowInTaskbar = false;
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.WindowState = System.Windows.Forms.FormWindowState.Minimized;
            this.ResumeLayout(false);

        }

        #endregion


    }
}
